﻿using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Jlvier.TaobaoShowcase.Service;

namespace ShowWindowIntelligence
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            using (var authenticationForm = new AuthenticationForm())
            {
                if (authenticationForm.ShowDialog()==DialogResult.OK)
                {
                    SessionKey.Create(authenticationForm.Authenticcode);
                }
            }
        }

        private void OnExitClick(object sender, EventArgs e)
        {
            Close();
        }
        private void OnApplyClick(object sender, EventArgs e)
        {
            try
            {
                IShowWindowRule rule = new WillDelist(new List<Product>(), new List<Product>());
                rule.Apply();
            }
            catch(RecommendationOverloadException)
            {
            }
            catch(Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void OnRequirementSelected(object sender, EventArgs e)
        {
            using(var dialog = new ProductSelectionForm())
            {
                if (dialog.ShowDialog() == DialogResult.Cancel) return;
                dialog.Selection.ToString();
            }
        }
    }
}
